package com.lgc.kt_jetpack_android_edu.base

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.viewbinding.ViewBinding

abstract class BaseFragment <T: ViewBinding>: Fragment(){
    private lateinit var _binding:T
    protected val binding get()=_binding

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        _binding=getViewBinding(inflater,container)
        return _binding.root
    }
    abstract fun getViewBinding(inflater: LayoutInflater, container: ViewGroup?): T

    abstract fun initData()

    //Activity的onCreate()方法结束后调用这个方法,代表Activity创建完成
    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        initData()
    }
}